package com.jeeplus.modules.work.queue.service;


import com.jeeplus.database.datasource.annotation.DS;
import com.jeeplus.modules.work.queue.entity.QuquEntity;
import com.jeeplus.modules.work.queue.mapper.QueueMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@DS("queuing")
@Service
@RequiredArgsConstructor
@Slf4j
@Transactional
public class QueueService {

    private final QueueMapper mapper;

    public QuquEntity findQueueNow(Map<String,Object> map){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String format = df.format(new Date());
        map.put("time",format);
        QuquEntity queueNow = mapper.findQueueNow(map);
        return queueNow;
    }

    public List<Map<String,Object>> window(){
        return mapper.window();
    }
    public List<Map<String,Object>> staff(){
        return mapper.staff();
    }
    public Map<String,Object> queuingInfoStart(String number,String sysno){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String format = df.format(new Date());
        Map<String, Object> map = mapper.queuingInfo(format,number,sysno);
        boolean endtime = map.containsKey("endtime");
        if(endtime){
            map.remove("endtime");
        }
        return map;
    }
    public Map<String,Object> findHandleInfoByWindow(String windowId){
        return mapper.findHandleInfoByWindow(windowId);
    }
    public List<Map<String,Object>> getArea(){

        return mapper.getArea();
    }
    /**
     * 根据区划编号和窗口号获取窗口ID
     * @return
     */
    public String getWindowId(String sysno,String winNo){
        String windowId = mapper.getWindowId(sysno,winNo);

        return windowId;
    }

    /**
     * 根据员工工号和区划编号获取员工ID
     * @return
     */
    public String getStaffId(String sysno,String userNo){
        String staffId = mapper.getStaffId(sysno, userNo);
        return staffId;
    }
    public List<Map<String,String>> findStreetCode() {

        return mapper.findStreetCode();
    }
    public List<Map<String,String>> findQueueInfo(String areaId) {

        return mapper.findQueueInfo(areaId);
    }
    public List<Map<String,String>> getWindosInfo() {

        return mapper.getWindosInfo();
    }
}
